<script type="text/javascript">

	var data = <?php echo $chart_data;?>; //{minimo:'',maximo:'',nsamples:'',data:[[x1,y1],[x2,y2],...,[xn,yn]]}

	$j(document).ready(function(){

		var settings = new ChartSettings();
		settings.init('chartdiv',data);
		settings.setResetID('#btnResetZoom');
		settings.setChartTitle('Registro de Variabilidad de Distensión Arterial');
		settings.setXAxisLabel('Tiempo [ms]');
		settings.setYAxisLabel('Amplitud [%]');
		
		var mainSeries = new Series();
		mainSeries.init("final_segment",data.data);
		mainSeries.setLabel('Muestra:');
		mainSeries.setMainSeries(true);
		mainSeries.setConf({showMarker:false, label: mainSeries.getLabel()});

		var aodSeries = new Series();
		aodSeries.init("aod",<?php echo $aod_data;?>);
		aodSeries.setLabel('AOD:');
		aodSeries.setVisible(false);
		aodSeries.setConf({label: "AOD", show:false, color:"#ff5800"});
		
		var aosSeries = new Series();
		aosSeries.init("aos",<?php echo $aos_data;?>);
		aosSeries.setLabel('AOS:');
		aosSeries.setVisible(false);
		aosSeries.setConf({label: "AOS", show:false, color:"#c5b47f"});

		var iarSeries = new Series();
		iarSeries.init("iar",<?php echo $iar_data;?>);
		iarSeries.setLabel("IAR:");
		iarSeries.setVisible(false);
		iarSeries.setConf({label: "IAR", show:false, color:"#EAA228"});

		var tSeries = new Series();
		tSeries.init("t",<?php echo $t_data;?>);
		tSeries.setLabel('RET:');
		tSeries.setVisible(false);
		tSeries.setConf({label: "RET", show:false, color:"#579575"});

		ChartControl.init(settings);
		ChartControl.addSeries(mainSeries);
		ChartControl.addSeries(aodSeries);
		ChartControl.addSeries(aosSeries);
		ChartControl.addSeries(iarSeries);
		ChartControl.addSeries(tSeries);
		ChartControl.paint();
			
		$j('input[type="checkbox"]').click(function(){
			var check = $j(this);
			var checkVal = check.is(':checked'); 

			//Si es falso, es porque acaba de ser desclickeado
			//con lo cual debe ponerse en false el atributo y ocultar la serie
			check.attr("checked",checkVal);				
			ChartControl.toggleSeries(check.attr("name"));
		});
		
		
	});
	
</script>
